/**
 * 教研老师查看自己的课题列表，包含
 * 
 * /jiaoyan/topic/list
 */

 
const Topics= require('../../../models/researchTopics')

const utils = require('../../../utils/index')
const $ = require('../../../utils/common')

const get_topic_list = async function (req, res) {
    try {
        if (!req.body.year_id) {
            $.sendMessage(res, 1015, '参数year_id不能缺 少')
            return
        }

        const year = req.body.year_id

        var topic_list = await Topics.findAndCountAll({
            where: {
                years: year,
                teacher_user_name: req.user_name
            }
            // attributes: ['id', 'topic_name', 'topic_resource', 'research_direction', 'student_limit',
            // 'topic_status', 'topic_background', 'current_student', 'confirm_num']
        })

        if (topic_list == null) {
            $.sendMessage(res, 1015, '无效相关数据')
            return
        }

        res.json({
            code: 200,
            message: '获取成功',
            data: topic_list
        })
           
        // 日志
        utils.create_a_log(req, '科研题目管理', '浏览自己的课题列表')
        return
    }
    catch(error) {
        res.json({
            message: "抓到异常",
            error: 'error' + error
        })
        utils.create_a_log(req, '科研题目管理', '浏览自己的课题列表', '失败')
        return
    } 
}
    
module.exports = get_topic_list